package com.dhcc.sds.busi.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.busi.entity.SdsQcfitemExecresultEntity;
import com.dhcc.sds.busi.service.ISdsQcfitemExecresultService;


/**
 * 病种项目结果值
 * 
 * @ClassName: SdsQcfitemExecresultController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:09:15
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcfitemexecresult")
public class SdsQcfitemExecresultController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqcfitemexecresult/";

	@Autowired
	private ISdsQcfitemExecresultService sdsQcfitemExecresultService;
	

    /**
     * 跳转到病种项目结果值列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsqcfitemexecresult.html";
    }
	
    /**
     * 跳转到新增病种项目结果值
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdsqcfitemexecresult_add.html";
    }
	
	/**
     * 跳转到修改病种项目结果值
     */
    @RequestMapping("/to_update/{sdsQcfitemExecresultId}")
    public String toUpdate(@PathVariable Long sdsQcfitemExecresultId, Model model) {
        SdsQcfitemExecresultEntity sdsQcfitemExecresult = this.sdsQcfitemExecresultService.selectById(sdsQcfitemExecresultId);
        model.addAttribute("sdsQcfitemExecresult",sdsQcfitemExecresult);
        return PREFIX + "sdsqcfitemexecresult_edit.html";
    }

    /**
     * 获取病种项目结果值列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsQcfitemExecresultEntity> page = new PageFactory<SdsQcfitemExecresultEntity>().defaultPage();
        List<SdsQcfitemExecresultEntity> result = this.sdsQcfitemExecresultService.page(page,params);
        page.setRecords((List<SdsQcfitemExecresultEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增病种项目结果值
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQcfitemExecresultEntity sdsQcfitemExecresult) {
        if (CommonUtil.isOneEmpty(sdsQcfitemExecresult)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsQcfitemExecresult.insert();
        return R.ok();
    }

    /**
     * 删除病种项目结果值
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsQcfitemExecresultId) {
	
        this.sdsQcfitemExecresultService.deleteById(sdsQcfitemExecresultId);

        return R.ok();
    }

    /**
     * 修改病种项目结果值
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsQcfitemExecresultEntity sdsQcfitemExecresult) {
        if (CommonUtil.isOneEmpty(sdsQcfitemExecresult)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQcfitemExecresultEntity old = this.sdsQcfitemExecresultService.selectById(sdsQcfitemExecresult.getId());

        old.setInCaseId(sdsQcfitemExecresult.getInCaseId());
        old.setformItemId(sdsQcfitemExecresult.getformItemId());
        old.setItemResult(sdsQcfitemExecresult.getItemResult());
        old.setExecType(sdsQcfitemExecresult.getExecType());
        old.setExecUser(sdsQcfitemExecresult.getExecUser());
        old.setExecDate(sdsQcfitemExecresult.getExecDate());
        old.setExecTime(sdsQcfitemExecresult.getExecTime());
        old.setInitValue(sdsQcfitemExecresult.getInitValue());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
